package com.liujun.spring4.demo.aop.aop.throwsadvice.listthrowadvice;

import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;
import java.sql.SQLException;

/**
 * 异常增强对业务 方法进行增强处理，统一捕捉抛出的异常并回滚事务
 *
 * <p>throwAdvice异常抛出增强没有定义任何的方法，它是一个标签接口，
 *
 * <p>在运行期Spring使用反射机制进行自行判断，必须采用以下签名形式定义异常执行的增强方法
 *
 * <p>void afterThrowing([Method method,Object[] args,Object targer],Throwable);
 *
 * <p>前三个参数可选要么提供，要都都不提供
 *
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/22
 */
public class TransactionManagerSQLException implements ThrowsAdvice {

  public void afterThrowing(Method method, Object[] args, Object target, SQLException exception)
      throws Throwable {
    System.out.println("TransactionManagerSQLException afterThrowing start -------------------");
    System.out.println("method:" + method.getName());
    System.out.println("exception:" + exception.getMessage());
    System.out.println("argument:" + args);
    System.out.println("targer:" + target);
    System.out.println("success rollback transmanager");
    System.out.println("TransactionManagerSQLException afterThrowing over  -------------------");
  }
}
